<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>菜单增加</title>

</head>
<body>
<script>
    $(function () {
        $("#parentId").combotree({
            url: ctx + 'sys/menu/all',
            id: 'id',
            textField: 'name',
            parentField: 'parentId',
            label: '父菜单:',
            labelAlign: 'right'
        })

        $("#sort").numberbox({
            min:0,
            max:9999,
            label: '展示顺序:',
            labelAlign: 'right',
            required:true,
            missingMessage:'范围 0-9999',
            invalidMessage:'范围 0-9999'
        })

        $("#stateSwitch").switchbutton({
            onText:'开',
            offText:'关',
            onChange:function (checked) {
                if (checked) {
                    $("#stateSwitch").switchbutton('setValue', 1)
                    $("#expandState").val(1)
                } else {
                    $("#stateSwitch").switchbutton('setValue', 0)
                    $("#expandState").val(0)
                }
            }

        })

    })


    function clearParentId() {
        $('#parentId').combotree('clear');
    }


    function subForm() {
        $.messager.progress({
            title: '提示',
            text: '数据处理中，请稍后....'
        });
        // $.messager.progress();
        $("#entityForm").form('submit', {
            onSubmit: function () {
                var isValid = $(this).form('validate');
                if (!isValid) {
                    $.messager.progress('close');	// hide progress bar while the form is invalid
                }
                return isValid;	// return false will stop the form submission
            },
            success:function (result) {
                // console.log(result);
                result = eval('(' + result + ')');
                $.messager.progress('close');
                $.messager.alert('提示',result.msg,'info');
                if (result.code == 0) {
                    $('#form').dialog('close');
                    //删除datagrid的选中状态，否则上次操作的缓存会存在
                    $("#treegrid").treegrid('clearSelections');
                    $('#treegrid').treegrid("reload");
                }
            }
        })
    }

    /**
     * 关闭dialog框
     */
    function closeForm() {
        $('#form').dialog('close');
    }
</script>
<!--/*@thymesVar id="menuEntity" type="com.freedom.start.sys.entity.MenuEntity"*/-->
<form th:action="@{/sys/menu/save}" id="entityForm"  th:object="${menuEntity}" th:method="post">
    <input type="hidden" th:field="*{id}">
    <div style="margin-bottom: 10px"></div>
    <div style="margin-bottom: 10px">
        <input th:field="*{name}" class="easyui-textbox" data-options="required:true,label:'名称:'" style="width:80%"/>
    </div>
    <div style="margin-bottom: 10px">
        <input th:field="*{code}" class="easyui-textbox" data-options="required:true,label:'代码:'" style="width:80%">
    </div>
    <div style="margin-bottom: 10px">
        <!--父菜单 选择树-->
        <input th:field="*{parentId}" id="parentId" style="width:80%">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-no'" onclick="clearParentId()">清除</a>
    </div>
    <div style="margin-bottom: 10px">
        <input th:field="*{url}" class="easyui-textbox" data-options="label:'连接:'" style="width:80%"/>
    </div>

    <div style="margin-bottom: 20px">
        <input type="text" th:field="*{sort}">
    </div>

    <div style="margin-bottom: 20px">
        <input th:field="*{iconClass}" class="easyui-textbox" data-options="label:'图标名称:'" style="width:80%">

    </div>

    <div style="margin-bottom: 20px">
        <span class="textbox-label textbox-label-before" style="text-align: right;">状态:</span>
    <!-- 用于展示后台数据-->
        <input  id="stateSwitch" th:checked="*{expandState}">
    <!--   真正要提交到后台的数据   -->
        <input  type="hidden" th:field="*{expandState}" >
    </div>
    <div style="margin-bottom:20px;text-align: center">
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" onclick="subForm()">保 存</a>
        <a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-undo'" onclick="closeForm()">返回</a>
    </div>
</form>
</body>
</html>